<?php

namespace App\Http\Controllers\Log;

use App\Models\Log\AuthLog;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class AuthController extends Controller
{
    public function index(Request $request)
    {
        if ($request->ajax()) {

            $rows = $request->get("rows");

            $AuthLog = $this->filters($request, new AuthLog());

            $paginator = $AuthLog->orderBy($request->get("sidx"), $request->get("sord"))->paginate($rows);

            $rows = [];
            foreach ($paginator as $page) {
                $page->time = substr($page->time, 0, 18);
                $rows[] = $page;
            }

            $data = [
                'rows' => $rows,
                'total'=> $paginator->lastPage(),
                'page' => $paginator->currentPage(),
                'records' => $paginator->count(),
            ];

            return response()->json($data);

        } else {
            return view('log/auth/index');
        }
    }
}
